package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsPriorityMapper;
import net.anzhuo.entity.GsPriority;
import net.anzhuo.service.GsPriorityService;

@Service
public class GsPriorityServiceImpl implements GsPriorityService {

	@Autowired
	private GsPriorityMapper gsPriorityMapper;
	
	@Override
	public GsPriority getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsPriorityMapper.getById(id);
	}

	@Override
	public List<GsPriority> getBycoMd5(GsPriority coMd5) {
		// TODO Auto-generated method stub
		return gsPriorityMapper.getByCoMd5(coMd5);
	}

	@Override
	public PaginationVO<GsPriority> getListWithPage(GsPriority gsCheck) {
		PaginationVO<GsPriority> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsPriorityMapper.getListWithPage(gsCheck));
		paginationVO.setTotalCount(gsPriorityMapper.getCount(gsCheck.getKeyNo()));
		paginationVO.setTotalPage((gsPriorityMapper.getCount(gsCheck.getKeyNo()) + gsCheck.getPageSize() -1)  / gsCheck.getPageSize());
		paginationVO.setPageNo(gsCheck.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsPriority> getList() {
		// TODO Auto-generated method stub
		return  gsPriorityMapper.getList();
	}

	@Override
	public List<GsPriority> getList(GsPriority gsCheck) {
		// TODO Auto-generated method stub
		return gsPriorityMapper.getListByQuery(gsCheck);
	}
	
	@Override
	public List<GsPriority> getByKeyNo(GsPriority gsCheck) {
		// TODO Auto-generated method stub
		return gsPriorityMapper.getByKeyNo(gsCheck);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsPriority gsCheck) {
		// TODO Auto-generated method stub
		gsPriorityMapper.update(gsCheck);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsPriority gsCheck) {
		// TODO Auto-generated method stub
		gsPriorityMapper.save(gsCheck);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsPriority gsCheck = gsPriorityMapper.getById(id);
		if (gsCheck == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsPriorityMapper.update(gsCheck);

	}

	@Override
	public int getCount(GsPriority gsPriority) {
		// TODO Auto-generated method stub
		return gsPriorityMapper.getCount(gsPriority.getKeyNo());
	}

	@Override
	public List<GsPriority> getByStatusBasicList(GsPriority gsPriority) {
		// TODO Auto-generated method stub
		return gsPriorityMapper.getByStatusBasicList(gsPriority);
	}

}
